﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BranchOfSansar.Sansar.Register;

namespace BranchOfSansar.Register.Products
{
    public partial class frmEquipment : Form
    {
        private bool IsChoosing = false;
        public Equipment SelectedEquipment = null;
        public frmEquipment()
        {
            InitializeComponent();
            BindEquipment();
            IsChoosing = false;
        }

        public frmEquipment(bool choose)
            : this()
        {
            IsChoosing = choose; 
        }

        private void BindEquipment()
        {
            using (RegisterClient reg = new RegisterClient(Globals.Token))
            {
                gridEquipment.DataSource = reg.EquipmentList();
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmRegEquipment frm = new frmRegEquipment();
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                BindEquipment();
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (viewEquipment.SelectedRowsCount < 1)
            {
                Globals.Warr("Өгөгдөл сонгогдоогүй байна!");
                return;
            }
            Equipment eq = (Equipment)viewEquipment.GetRow(viewEquipment.GetSelectedRows()[0]);
            frmRegEquipment frm = new frmRegEquipment(eq);
            if (frm.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                BindEquipment();
            }
        }

        private void gridEquipment_DoubleClick(object sender, EventArgs e)
        {
            if (viewEquipment.SelectedRowsCount > 0)
            {
                SelectedEquipment = (Equipment)viewEquipment.GetRow(viewEquipment.GetSelectedRows()[0]);
                this.DialogResult = System.Windows.Forms.DialogResult.Yes;
            }
        }

        private void frmEquipment_Load(object sender, EventArgs e)
        {

        }
    }
}
